Expressions


Description

Expressions can be used in KnowledgeWright anywhere a value is expected. Expressions can include any object. If the value for that object is not known, then the reasoning engine will determine its value before calculating the value of the expression.

Comparators

You can use these comparators:

equal
\=
not equal
<
less than
>
greater than
<=
less than or equal
>=
greater than or equal 
not(expr)
the expression is false
contains "text"

checks if a text value contains a particular set of characters, words or phrases

contains_nocase "text"
checks if a text value contains another text value regardless of case
numberX - numberY
the number is greater than or equal to numberX and less than or equal to numberY

The comparators <, >, <= and >= sort by numeric value for numbers and by the ASCII character codes for strings so 'A' < 'B', 'c' > 'D', '2' < 'E'.

The 'not' operator is especially useful with 'include' (described below). For example for 'behavior' rules:

conditions
value
not(dogs include kato and
dogs include ollie)
no_running_around

All of the facts on the if-side of the rule must either have questions or rules defined for them. In the examples above, 'environmentNameVer' is fact that is defined by question, which means the user is queried for the value. The fact 'language' is defined by a rule, which means its value is derived from other facts.

Facts with Multiple Values

KnowledgeWright also supports the concept of having a fact with multiple values (for example questions with type menu_multiple_choices, sql queries and rules with multiple values). These special comparators can be used for multi-valued facts:

include
included in list
exclude
not included in list 

For example to check the multivalued fact 'whys' you could use 'include' as follows for the rule 'tool':

conditions
value
whys include "Intelligent components for Internet" or
what = "Website construction" or
what = "Other"
webls

Functions

You can use these functions:

age(birthdate)
the age of someone or something based on the birthdate
date(year, month, day)
the date value representing the specified year, month and day
find(column from data_table where conditions)
returns the value of the named column where the other columns meet the condtions specified for other columns in the data_table (note, this returns the first value matching the conditions)
integer(expression)
returns the integral value of the expression
length(expression)

if expression is a list, returns the number of items in the list

if expression is a string, returns the number of characters in that string

string_to_date(string)
converts the text value into a date using the format specified in the main knowledgebase object
system(paramater)
returns the value of an initial value passed programmatically into the KWI with kwi(id, initalize(parameters), ...). These can only be used in text fields. Typically it is used to pass the cgi_parameters to subsequent invocations of the CGI interface. Other parameters of interest include the directory, temp_directory and kb_file.

Constants

You can use these constants:

default
a constant value for rule_sets that specifies a default condition that is always matches (synonym for true)
true
a constant value for rule_sets that specifies a condition that always matches (synonym for default)
*
a constant value for rules_tables that matches any value

Also, see the date constants below.

Arithmetic Operators

Formulas can be used in rules for determining the value of a fact. KnowledgeWright supports addition, subtraction, multiplication, division and exponentiation via the following operators:

+ addition
-
subtraction
*
multiplication
/
division
**
exponentiation

For example here's a rule for 'area':

conditions
value
shape = "circle"
pi * radius ** 2

Date Handling

You can use dates in rules and perform arithmetic on them. A date is represented in KnowledgeWright as date(Year, Month, Day (where the year is a full, 4-digit number). There are names for special dates as follows:

today
yesterday
tomorrow
last_week
next_week
last_month
next_month
last_year
next_year


Users can enter dates as fill-in-the-blank questions. The format for user entry is specified in the main knowledgebase object (under date_format) and defaults to MM/DD/YYYY. This is transformed automatically into date(Year, Month, Day). For example, you can test if today is before Christmas 2001:

conditions
value
today < date(2001, 12, 25)
"before Christmas"
Once a date is in KnowledgeWright you can perform date arithmetic. For example, to determine how many days until Christmas:
conditions
value
date(2001, 12, 25) - today < 30
"shop quick"
date(2001, 12, 25) - today < 60
"shop slow"
You can use the following values in date arithmetic:

W weeks
D days
M months
Y years

This allows you to write:

conditions
value
today + 1 months > date(2001, 12, 25)
"shop quick"
today + 1 months < date(2001, 12, 25)
"shop slow"

Copyright ©1996-2002 Amzi! inc. All Rights Reserved. Amzi!, KnowledgeWright and WebLS are registered trademarks and Subscription Plus and Logic Server are trademarks of Amzi! inc.